package com.cskaoyan.day03.generic4;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.InvocationHandler;

import java.lang.reflect.Method;

/**
 * @author stone
 * @date 2022/01/29 10:54
 */
public class ProxyUtil {

    public static <T> T getProxy(T target) {
        //为啥用cglib动态代理
        Object proxy = Enhancer.create(target.getClass(), new InvocationHandler() {
            @Override
            public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
                System.out.println("正道的光");
                Object invoke = method.invoke(target, objects);
                return invoke;
            }
        });
        return (T) proxy;
    }
}
